<div class="xinxi-guanli">
<div class="xinxi-title">
<ul id="details-ul" class="clearfix">
				<li  class="hover"><a title="管理供应信息"  href="/product/sell">供应信息</a></li>
				<li ><a title="管理采购信息"  href="/product/buy">采购信息</a></li>
			</ul>
</div>
 <div id="details-con-1" class="xinxi-guanli-box">
<form id="applyform" action="" method="post" onsubmit="return addContent();">

<table class="grinfo">

  <tbody>
  <tr>
		<th><span class="red">*</span>产品类型：</th>
            <td colspan="2">        
                    <input type="radio" value="1" <if condition="($data.pclass eq 1)">checked="checked"</if>  name="pclass" >现货/标准品
                    &nbsp;&nbsp;&nbsp;&nbsp;
                    <input type="radio" value="2" <if condition="($data.pclass eq 2)">checked="checked"</if> name="pclass" >二手/闲置
                    &nbsp;&nbsp;&nbsp;&nbsp;
                    <input type="radio" value="3" <if condition="($data.pclass eq 3)">checked="checked"</if> name="pclass" >库存/尾货
				
              </td>
	</tr>
	<tr>
		<th><span class="red">*</span>分类栏目：</th>
		<td colspan="2">
		<select id="catid" class="inp inw" style="width:85px;" name="catid">
		{$Categoryhtml}
		</select>
		<span id="typeidhtml">
		<select id="sontypeid" class="inp inw" style="width:105px;" name="typeid">
			{$SonCategoryhtml}
		</select>
		</span>
		<span id="catidhtml" class="fgrey"></span>
		
		</td>
	</tr>

	<tr>
		<th><span class="red">*</span>发货地址：</th>
		<td colspan="2">
		<select id="province" class="inp inw" style="width:140px;" name="province">
			{$Areahtml}
		</select>
		<span id="cityhtml">
		<select id="city" class="inp inw" style="width:100px;" name="city">
			{$SonAreahtml}
		</select>
		</span>
		<span id="provincehtml" class="fgrey"></span>
		</td>
	</tr>
	
	
	<tr>
		<th><span class="red">*</span>信息标题：</th>
		<td><input type="text" value="{$data.title}" id="title" style="width:430px;" name="title" class="inp inw">
		<input type="hidden" name="id"  value="{$data.id}" >
		</td>
	</tr>
	
	<tr>
		<th><span class="red">*</span>关键词：</th>
		<td><input type="text" value="{$data.keywords}" id="keywords" style="width:430px;" name="keywords" class="inp inw"></td>
	</tr>


	

	<tr>
		<th><span class="red">*</span>价格：</th>
		<td colspan="2">
			<input type="text" name="price" id="price" value="{$data.price}" style="width:60px;"  maxlength="30" class="inp"> 
			<span id="pricehtml" class="fgrey">元 (0元表示面议)</span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="red">*</span><span style="font-size:14px">计量单位：</span>
			<select id="unit" class="inp inw" style="width:85px;" name="unit">
					<option value="0" <if condition="($data.unit eq 0)">selected="selected"</if> >手动填写</option>
					<option value="1" <if condition="($data.unit eq 1)">selected="selected"</if> >平方米</option>
					<option value="2" <if condition="($data.unit eq 2)">selected="selected"</if> >立方米</option>
					<option value="3" <if condition="($data.unit eq 3)">selected="selected"</if> >件</option>
					<option value="4" <if condition="($data.unit eq 4)">selected="selected"</if> >个</option>
					<option value="5" <if condition="($data.unit eq 5)">selected="selected"</if> >套</option>
					<option value="7" <if condition="($data.unit eq 7)">selected="selected"</if> >米</option>
					<option value="8" <if condition="($data.unit eq 8)">selected="selected"</if> >吨</option>
					<option value="11" <if condition="($data.unit eq 11)">selected="selected"</if> >袋</option>
					<option value="12" <if condition="($data.unit eq 12)">selected="selected"</if> >桶</option>
			</select>
			<span id="unithtml" style="<if condition="($data.unit neq 0)">display:none;</if>">
			<input type="text" name="unitname" style="width:80px;"  id="unitname" value="{$data.unitname}" maxlength="30" class="inp"> 
			<span id="unitnamehtml" class="fgrey">(系统无此计量单位,请手动填写)</span>
			</span>
		</td>
	</tr>

	
	<tr>
		<th><span class="red">*</span>发货周期：</th>
		<td colspan="2">
			<input type="text" name="cycle" id="cycle" value="{$data.cycle}"  style="width:60px;"  maxlength="30" class="inp" > <span class="fgrey" id="cyclehtml">天(填写的数字为1至365的天数范围内)</span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="red">*</span><span style="font-size:14px">信息有效期：</span>
			<select id="valid" class="inp inw" style="width:85px;" name="valid">
		<option value="48" <if condition="($data.valid eq 48)">selected="selected"</if> >一年内</option>
		<option value="24" <if condition="($data.valid eq 24)">selected="selected"</if> >六个月内</option>
		<option value="12" <if condition="($data.valid eq 12)">selected="selected"</if> >三个月内</option>
		<option value="4" <if condition="($data.valid eq 4)">selected="selected"</if> >一个月内</option>
		</select>
		</td>
	</tr>

	<tr>
		<th><span class="red">*</span>最小起订量：</th>
		<td colspan="2">
			<input type="text" name="least" id="least" style="width:60px;" value="{$data.least}" class="inp inw"> <span id="leasthtml" class="fgrey">(0表示不限)</span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="red">*</span><span style="font-size:14px">供货总量说明：</span>
			<input type="text" name="totalinfo" id="totalinfo" style="width:250px;" value="{$data.totalinfo}" class="inp inw" > <span id="totalinfohtml"  class="fgrey">(文字在20个字以内)</span>
			
		</td>
	</tr>


	
	
	<tr>
		<th valign="top"><span class="red">*</span>产品摘要：</th>
		<td>
			<textarea name="description" class="grtextarea" style="width:600px;height:60px;" id="description">{$data.description}</textarea>
			<br>
			<span class="fgrey" id="descriptionhtml" >(注:产品摘要为产品介绍的简单说明，不能少于20个字)</span>
		</td>
	</tr>

	<tr>
		<th valign="top"><span class="red">*</span>产品介绍：</th>
		<td>
			<textarea name="content" class="grtextarea" style="width:505px;height:280px;" id="content">{$data.ProductData.content}</textarea>
			<span id="contenthtml" class="fgrey"><span class="red">*</span>&nbsp;&nbsp;产品介绍文字不能少于50个字.请从产品性能、用途、包装、售后服务等方面来描述，建议您在详细说明中插入产品细节图。
温馨提示：为保证您发布内容格式的正确，请直接在编辑窗口中进行编辑，不要直接粘贴从word里复制的内容！</span>
		</td>
	</tr>

	<tr>
				    <th>产品图片：</th>
					<td>
                        <div class="upload_img_area"  style="margin-top:1px;">
							<ul id="picturelist" class="clearfix">
								
								<foreach name="attachment" item="vo">

								<li id="picnum{$vo.aid}">
								<img src="http://user.dushijia.com/Public/Uploads/{$vo.filepath}" width="120px" height="180px" />
								 <input class="pic" type="hidden" value="{$vo.aid}" name="picid[]"  >
								<input class="pic" type="hidden" value="{$vo.filepath}" name="picimg[]"  >
								<a class="icon del_ico" onclick = "delimages(this,{$vo.aid},1)">删除</a>
								<div class="type_sel cover_seting">
								   <input class="ordersnums" type="hidden" size="3" value="{$vo.aid}" name="orders[]">
									<input type="radio" name="thumb" value="{$vo.filepath}" <if condition="($vo.filepath eq $thumb)">checked="checked"</if> >
									<em class="radio_icon <if condition="($vo.filepath eq $thumb)">radio_cur</if>" ></em>
									<span class="mr10">封面</span>&nbsp;&nbsp;&nbsp;&nbsp;
									<span title="上一个" onclick="PrevImage({$vo.aid})"  class="icon ico_prev">上一个</span>
									<span title="下一个" onclick="NextImage({$vo.aid})" class="icon ico_next">下一个</span>
								</div>
								</li>
								</foreach>
							</ul>
							 <input type="hidden" name="nowpicnums" id="nowpicnums" value="0" >
						</div>
						<br/>
						<div style="float:left;">
                            <div id="filePictures"></div>
                            <div id="uploadpicture">
                                <span id="images" name="images" ></span>
                            </div> 
                        </div>
						<br/>
						<br/>

						<p class="fgrey" ><i class="icon i_s_plaint"></i>注意：可一次选择多张图片批量上传。请上传3-5张清晰无水印截图的！特别提醒：【<b>正视角的图片上传效果会更好!</b>】</p>
                    </td>
    </tr>
	


	
	<tr>
		<th>品牌：</th>
		<td colspan="2">
			<input type="text" name="brands" id="brands" style="width:450px;" value="{$data.ProductData.brands}"  class="inp inw">
			<span id="txtAddress_Tip"></span>
		</td>
	</tr>
	<tr>
		<th>型号：</th>
		<td>
			<input type="text" name="model" id="model" style="width:450px;" value="{$data.ProductData.model}"  class="inp inw">
		</td>
	</tr>

	<tr>
		<th>规格：</th>
		<td>
			<input type="text" name="standard" id="standard" style="width:450px;" value="{$data.ProductData.standard}" class="inp inw">
		</td>
	</tr>
	
	
	
	
	
	
	
	
	
	<tr>
		<th>&nbsp;</th>
		<td colspan="2">
			<label id="butt" class="butt">
				<input type="submit" name="btnSubmit" value="修改产品" id="btnSubmit" class="btns">
			</label>
		</td>
	</tr>
</tbody>
</table>

{__TOKEN__}
</form>

  </div>
  
    
</div>

<script type="text/javascript" src="/public/js/plugin/jquery.uploadify-3.1.min.js"></script>
<script type="text/javascript" src="/public/js/plugin/tinymce/tinymce.min.js"></script>
<script type="text/javascript" src="/public/js/plugin/layer/jquery.layer.js"></script>
<script type="text/javascript" src="/public/js/plugin/jquery.form.js"></script>
<script type="text/javascript" src="/public/js/plugin/jquery.validate.js"></script>
<script type="text/javascript" src="/public/js/product.js"></script>
<script type="text/javascript">
function addContent()
{
	var content = tinyMCE.get('content').getContent();
    $("#content").val(content);
}

//选取文件的函数，后台特有
tinymce.init({
    selector: "textarea#content",
    theme: "modern",
	language :"zh_CN",
    width: 600,
    height: 300,
    plugins: [
         "advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker",
         "searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
         "save table contextmenu directionality emoticons template paste textcolor"
   ],
   content_css: "css/content.css",
   toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | l      ink image | print preview media fullpage | forecolor backcolor emoticons", 
   style_formats: [
        {title: 'Bold text', inline: 'b'},
        {title: 'Red text', inline: 'span', styles: {color: '#ff0000'}},
        {title: 'Red header', block: 'h1', styles: {color: '#ff0000'}},
        {title: 'Example 1', inline: 'span', classes: 'example1'},
        {title: 'Example 2', inline: 'span', classes: 'example2'},
        {title: 'Table styles'},
        {title: 'Table row 1', selector: 'tr', classes: 'tablerow1'}
    ]
 });   

$(document).ready(function(){
	
	showButton();

	$("#catid").bind("change", function(){
		var pid = $(this).val();
		
		$.post('/ajax/category',{pid:pid},function(result){
			$("#typeidhtml").html(result.data);
		});
	});

	$("#province").bind("change", function(){
		var pid = $(this).val();
		
		$.post('/ajax/area',{pid:pid},function(result){
			$("#cityhtml").html(result.data);
		});
	});

	$("#unit").bind("change", function(){
		var unit = $(this).val();
		if(unit>0){
			$("#unithtml").hide();
		}else{
			$("#unithtml").show();
		}
		
	});

	

	$("#images").uploadify({
			swf              : '/public/js/plugin/uploadify.swf',
			uploader         : "/public/upload",
			cancelImg        : '/public/images/cancel.gif',
			formData      : {'uid' : '3551726'},
			removeTimeout    : 0,
			debug    : 0,
			queueID          : 'filePictures',
			method		     : 'POST',
			fileTypeDesc     : '注意:您只能上传jpeg,png,gif,zip格式的文件!',
			fileTypeExts     : '*.jpg;*.jpeg;*.gif;*.png',
			buttonImage	     : '/public/images/upload_file.png',
			width		     : '100',
			height		     : '35',	
			auto             : true,
			multi            : true,
			onUploadSuccess  : function(file, data, response) {
					var response=eval("("+data+")");
					
					if(response.status){
						var picnum = $("#nowpicnums").val();
						var str='<li id=picnum'+picnum+'>'+response.data.head+'<a class="icon del_ico" onclick="delimages(this,'+picnum+')">删除</a>\
						<br>'+response.data.end+'<em class="radio_icon" ></em>\
						<span class="mr10">封面</span>&nbsp;&nbsp;&nbsp;&nbsp;\
						<span title="上一个" onclick="PrevImage('+picnum+')" class="icon ico_prev">上一个</span>\
						<span title="下一个" onclick="NextImage('+picnum+')" class="icon ico_next">下一个</span>\
						</div></li>';
						$('#picturelist').append(str);
						$("#filePictures").html('');
						$('#msg_pic').html('');
						$("#nowpicnums").val(parseInt(parseInt(picnum)+1));
					} else {
						$.layer({v_title:'出错提示',v_msg:response.info,v_shade:false,v_btns:1,v_area:['410px','220px']});
				}
				 
		  },
		  onUploadStart : function(file) {
			  var imgsize = $("#picturelist").find("img").size();
			  if(parseInt(imgsize)>=6){
				$.layer({
						v_msg:'对不起，您只能上传最多6张图片!',
						v_shade:false,
						v_title:'图片超过',
						v_btns:1,
						v_btn:['确定'],
						v_showtime:2
				});
				$('#images').uploadify('disable', true);
				$('#images').uploadify('stop');
				$('#images').uploadify('cancel');
			  }
			  
		  }, 
		  onQueueComplete : function(queueData) {
				showButton();
		  } 
	});




	$("#applyform").validate({
	  		focusInvalid: true ,
			errorClass: "err_ipt",
			ignore: "",
			rules: { 
				
				'catid': {
	                required: true,
					digits: true
	            },
	            'typeid': {
	                required: true,
					digits: true
	            },
				'province': {
	                required: true,
					digits: true
	            },
	            'city': {
	                required: true,
					digits: true
	            },
				
				'title':{
					required: true,
					minlength:5
				}, 
				'keywords': {
					required: true,
					minlength:2
	            },
	            'price': {   
	                required: true,
					floornum: true
	            },
				
				'cycle': {   
	                required: true,
					digits: true
	            },
	            'least': {   
	                required: true,
	                digits: true
	            },
	            'totalinfo': {
	                required: true,
					maxlength:20
	            },
				'description':{
					required: true,
					minlength:20
				}, 
				'content':{
					required: true,
					minlength:50
				}
	        },   
	        messages: {
				'catid': {
					required: '<span class="fgrey"><img src="/public/images/error.gif" />&nbsp; 请选择产品大分类.</span>',
					digits: '<span class="fgrey"><img src="/public/images/error.gif" />&nbsp; 请选择产品大分类.</span>'
				},
				'typeid': {
					required: '<span class="fgrey"><img src="/public/images/error.gif" />&nbsp; 请选择产品小分类.</span>',
					digits: '<span class="fgrey"><img src="/public/images/error.gif" />&nbsp; 请选择产品小分类.</span>'
				},
				'province': {
					required: '<span class="fgrey"><img src="/public/images/error.gif" />&nbsp; 请选择地区.</span>',
					digits: '<span class="fgrey"><img src="/public/images/error.gif" />&nbsp; 请选择地区.</span>'
				},
				'city': {
					required: '<span class="fgrey"><img src="/public/images/error.gif" />&nbsp; 请选择省市.</span>',
					digits: '<span class="fgrey"><img src="/public/images/error.gif" />&nbsp; 请选择省市.</span>'
				},
	        	'title':{
	        		required:'<span class="fgrey"><img src="/public/images/error.gif" />&nbsp; 请填写信息标题,例如:求购木地板.</span>',
	        		minlength: jQuery.format('<span class="fgrey"><img src="/public/images/error.gif" />&nbsp; 信息标题不得少于{0}个字.</span>')
	            },
	            'keywords': {
	            	required:'<span class="fgrey"><img src="/public/images/error.gif" />&nbsp; 请填关键词，例如:地板</span>',
	            	floornum:'<span class="fgrey"><img src="/public/images/error.gif" />&nbsp; 关键词不得少于{0}个字.</span>'
				},
				'price': {
					required: '<span class="fgrey"><img src="/public/images/error.gif" />&nbsp; 请填价格.</span>',
					floornum: '<span class="fgrey"><img src="/public/images/error.gif" />&nbsp; 请填数字.</span>'
				},
				'cycle': {
					required: '<span class="fgrey"><img src="/public/images/error.gif" />&nbsp; 请填发货周期.</span>',
					digits: '<span class="fgrey"><img src="/public/images/error.gif" />&nbsp; 请填数字.</span>'
				},
				'least': {
					required: '<span class="fgrey"><img src="/public/images/error.gif" />&nbsp; 请填起订量.</span>',
					digits: '<span class="fgrey"><img src="/public/images/error.gif" />&nbsp; 请填数字.</span>'
				},
				'totalinfo': {
					required: '<span class="fgrey"><img src="/public/images/error.gif" />&nbsp; 请供货总量.</span>',
					maxlength: jQuery.format('<span class="fgrey"><img src="/public/images/error.gif" />&nbsp;文字在20个字以内</span>')
				},
				'description':{
	        		required:'<span class="fgrey"><img src="/public/images/error.gif" />&nbsp;产品摘要为产品介绍的简单说明，不能少于20个字.</span>',
	        		minlength: jQuery.format('<span class="fgrey"><img src="/public/images/error.gif" />&nbsp; 产品摘要为产品介绍的简单说明，不能少于{0}个字.</span>')
	            },
				'content':{
	        		required:'<span class="fgrey"><img src="/public/images/error.gif" />&nbsp; 请填写产品产品介绍,且文字不能少于50个字.</span>',
	        		minlength: jQuery.format('<span class="fgrey"><img src="/public/images/error.gif" />&nbsp; 产品介绍信息不得少于{0}个字.</span>')
	            }
				
			},
			errorPlacement: function(error, element) {
				
				if ($(element).attr("name")=='catid') {
					if(parseInt($("#catid").val())==0){
						$("#catidhtml").html(error);
						return true;
					}
		        }

				if ($(element).attr("name")=='typeid') {
					if(parseInt($("#sontypeid").val())==0){
						$("#catidhtml").html(error);
						return true;
					}
		        }

				if ($(element).attr("name")=='province') {
					if(parseInt($("#province").val())==0){
						$("#provincehtml").html(error);
						return true;
					}
		        }

				if ($(element).attr("name")=='city') {
					if(parseInt($("#city").val())==0){
						$("#provincehtml").html(error);
						return true;
					}
		        }
				
				if ($(element).attr("name")=='price') {
		        	$("#pricehtml").html(error);
		            return true;
		        }

				if ($(element).attr("name")=='unitname'){
					if(parseInt($("#unit").val())==0){
						$("#unitnamehtml").html(error);
						return true;
					}
				}

				if ($(element).attr("name")=='cycle') {
		        	$("#cyclehtml").html(error);
		            return true;
		        }

				if ($(element).attr("name")=='least') {
		        	$("#leasthtml").html(error);
		            return true;
		        }

				if ($(element).attr("name")=='totalinfo') {
		        	$("#totalinfohtml").html(error);
		            return true;
		        }

				if ($(element).attr("name")=='description'){
					$("#descriptionhtml").html(error);
					return true;
				}
				
				if ($(element).attr("name")=='content') {
		        	tinyMCE.get('content').focus();
					$("#contenthtml").html(error);
					return true;
		        }
		        
		        error.insertAfter(element);
		    },
			success: function(label) {
				label.html('<span class="f_prompt"><img src="/public/images/yes.gif" /></span>').addClass("success");
			},
			submitHandler: function(form) {
				
				jQuery(form).ajaxSubmit({
					target: "#result",
					beforeSubmit:disableForm,
			        success:submitForm, 
			        url:'/product/edit',       
			        type:'post',      
			        dataType:'json'
				});
			}
		});
	  	function disableForm(){
			$('#applyform').find("input[type='submit']").attr("disabled",true);
			$('#applyform').find("input[type='submit']").val("正在修改,请稍等...");
			$.layer({
				v_title:'修改中',
				v_btns:0,
				v_msgtype:0,
				v_shade:false,
				v_area : ['300px','150px'],
				v_msg:'<div class="">\
							<div class="">\
							   <font color="green">数据正在提交到服务器进行发布,<br/>请耐心等待...</font>\
							</div>\
						</div>'
			});
			return true; 
		}

		function submitForm(responseText)  { 
			layer_close(true);
			if(responseText.status){
				if(responseText.data.id){
					$.layer({
						v_msg:responseText.info,
						v_title:'信息修改成功',
						v_btns:2,
						v_shade:false,
						v_btn:['返回列表','继续修改'],
						v_area:['410px','220px'],
						yes:function(){
							layer_close(true);
							location.href ="/product/sell";
						},
						no:function(){
							location.href = '/product/edit/id/'+responseText.data.id;
						}
					});
				}else{
					$.layer({v_msg:responseText.info,v_shade:false,v_title:'信息修改出错',v_showtime:2});
				}
				
			}else{
				
				$.layer({v_msg:responseText.info,v_shade:false,v_title:'信息修改出错',v_showtime:2});

				if(responseText.data.inputName == 'content'){
					tinyMCE.get('content').focus();
				}else{
					$("#"+responseText.data.inputName).focus();
				}
				$('#applyform').find("input[type='submit']").attr("disabled",false);
				$('#applyform').find("input[type='submit']").val("修改产品");
			}
		}


		
 });	
 </script>